﻿
@{
    ViewBag.Title = "Excess";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}


<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>超标设备查询</legend>
</fieldset>
<form class="layui-form" enctype="multipart/form-data">
    <div class="layui-form-item">
        <label class="layui-form-label">搜索</label>
        <div class="layui-input-block">
            <input type="text" id="SearchText" name="Title1" required lay-verify="required" onkeypress="getKey()" placeholder="输入设备名" class="layui-input" style="width:300px;float:left;">
            <input type="text" value="" style="display:none" />
            <label class="layui-form-label">开始时间</label>

            <input type="text" class="layui-input" id="TimeStart" style="width:150px;float:left">

            <label class="layui-form-label">结束时间</label>

            <input type="text" class="layui-input" id="TimeEnd" style="width:150px;float:left">
            <label class="layui-form-label"></label>
            <button type="button" class="layui-btn layui-btn-normal" style="float:left;" onclick="SearchFunc()"><i class="layui-icon">&#xe615;</i></button>


            @*<button type="button" class="layui-btn layui-btn-normal" onclick="apply()"><i class="layui-icon">&#xe63b;</i></button>*@
        </div>
    </div>
</form>
<table id="demo" lay-filter="UserTableList"></table>
<div style="font-size:12px;margin-top:10px;margin-bottom:10px;margin-left:15px;width:100%;position: absolute;left: 0px;bottom: 0px;">
    ©2020 德器(重庆)科技有限公司|DEQI(CQ) TECHNOLOGY.CO.,LTD 服务热线 400-9019-505
    @*重庆环元环境科学研究院*@
</div>

<script type="text/javascript">

    var table;
    var now = new Date();
    now.setHours(now.getHours() - 1);
    layui.use(['form', 'table', 'upload', 'layer', 'laydate'], function () {
        table = layui.table;
        var laydate = layui.laydate;
        var tab = parent.tab;
        var form = layui.form;
        var layer = layui.layer;
        var IsValidate = 0;
        var index;
        var MN;

        //执行一个laydate实例
        laydate.render({
            elem: '#TimeStart' //指定元素
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#TimeEnd' //指定元素
        });


        //第一个实例
        table.render({
            elem: '#demo'
            , method: 'post'
            //, height: 315
            , url: '/Panel/ExcessTableRequest' //数据接口
            , page: true //开启分页
            , where: { SortName: "DeviceId", Order: "Desc", Condition: " and 1=0" }
            , limits: [100, 500, 1000]
            , limit:100
            , cols: [[ //表头

                { field: 'DataTime', title: '时间', width: 180 }
                , { field: 'Name', title: '设备名称', width: 200 }
                , { field: 'Address', title: '设备地址', width: 200 }
                , {
                    field: 'Y1', title: '油烟', width: 180,
                    templet: function (d) {
                        return d.Y1 + "|" + d.Y2 + " (mg/m³)";

                    }
                }
                , {
                    field: 'V1', title: '非甲烷总烃', width: 180,
                    templet: function (d) {
                        return d.V1 + "|" + d.V2 + " (mg/m³)";

                    }
                }
                , {
                    field: 'K1', title: '颗粒物', width: 180,
                    templet: function (d) {
                        return d.K1 + "|" + d.K2 + " (mg/m³)";

                    }
                }
                //, {
                //    field: "operation", title: "操作", width: 150,
                //    templet: function (d) {
                //        return '' +
                //            '<a class="layui-btn layui-btn-xs" lay-event="Export">导出</a>';
                //    }
                //}
            ]]
        });

        table.on("tool(UserTableList)", function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if (layEvent == 'Export') {

                //var formstr = "PreEstId::" + data.PreEstId + "&Name::" + data.Name + "&ProjectName::" + ProjectName;
                //$.down('/Estimate/EstUserCSExport', formstr, 'post');
                MN = data.MN;
                index = layer.open({
                    type: 1,
                    area: ['900px', '150px'],
                    content: $("#DateTimeLayer") //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                });

            }

        });


        $("#BtnExport").on("click", function () {
            var TimeStart = $("#TimeStart").val();
            var TimeEnd = $("#TimeEnd").val();
            var formstr = "StartTime::" + TimeStart + "&TimeEnd::" + TimeEnd + "&MN::" + MN;
            $.down('/Panel/Data2Excel', formstr, 'post');




        });

    });

    //回车键
    function getKey() {
        if (event.keyCode == 13) {
            SearchFunc();
        }
    }

    function SearchFunc() {
        var text = $("#SearchText").val();
        var TimeStart = $("#TimeStart").val();
        var TimeEnd = $("#TimeEnd").val();
        if (TimeStart > TimeEnd || TimeStart == "" || TimeEnd == "") {
            alert("时间选择有误");
        }

        if (text == "") {
            table.reload("demo", {
                where: {
                    SortName: "DeviceId", Order: "Desc", Condition: " and Datatime>'" + TimeStart + " 00:00:00' and DataTime <'" + TimeEnd+" 23:59:59'"
                },
                page: {
                    curr: 1
                }
            });
        }
        else {
            table.reload("demo", {
                where: {
                    SortName: "DeviceId", Order: "Desc", Condition: " and Name like '%" + text + "%' and Datatime>'" + TimeStart + " 00:00:00' and DataTime <'" + TimeEnd + " 23:59:59'"
                },
                page: {
                    curr: 1
                }
            });
        }
    }

</script>


